<!-- 点击车辆进入预订汽车页面booking.php -->
<!DOCTYPE html>
<html>
<?php
include('session_customer.php'); // 包含用于验证会话的文件
if (!isset($_SESSION['login_customer'])) { // 如果当前没有登录会话
    session_destroy(); // 销毁会话
    header("location: customerlogin.php"); // 重定向到客户登录页面
}
?>
<title>预订汽车</title>

<head>
    <script type="text/javascript" src="assets/ajs/angular.min.js"> </script>
    <link rel="shortcut icon" type="image/png" href="assets/img/P.png.png">
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/w3css/w3.css">
    <script type="text/javascript" src="assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="assets/js/custom.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="assets/css/clientpage.css" />
</head>

<body ng-app="">
    <!-- 导航栏 -->
    <?php
    include './nav.php';
    ?>

    <div class="container" style="margin-top: 65px;">
        <div class="col-md-7" style="float: none; margin: 0 auto;">
            <div class="form-area">
                <form role="form" action="bookingconfirm.php" method="POST">
                    <br style="clear: both">
                    <br>

                    <?php
                    // 获取 URL 参数中的 car_id
                    $car_id = $_GET["id"];
                    // 构建 SQL 查询语句，根据 car_id 查询对应的车辆信息
                    $sql1 = "SELECT * FROM cars WHERE car_id = '$car_id'";
                    // 执行 SQL 查询
                    $result1 = mysqli_query($conn, $sql1);
                    // 如果查询结果非空，遍历结果集获取车辆信息
                    if (mysqli_num_rows($result1)) {
                        while ($row1 = mysqli_fetch_assoc($result1)) {
                            // 获取车辆信息
                            $car_name = $row1["car_name"]; // 车辆名称
                            $car_nameplate = $row1["car_nameplate"]; // 车牌号
                            $ac_price = $row1["ac_price"]; // 带空调的价格  豪华型
                            $non_ac_price = $row1["non_ac_price"]; // 不带空调的价格  经济型
                            $ac_price_per_day = $row1["ac_price_per_day"]; // 带空调的每日价格
                            $non_ac_price_per_day = $row1["non_ac_price_per_day"]; // 不带空调的每日价格
                        }
                    }
                    ?>
                    <h5> 选择的汽车:&nbsp; <b>
                            <?php echo ($car_name); ?>
                        </b></h5>
                    <h5> 车牌号:&nbsp;<b>
                            <?php echo ($car_nameplate); ?>
                        </b></h5>

                    <label>
                        <h5>开始日期:</h5>
                    </label>
                    <input type="date" name="rent_start_date" min="<?php echo date("Y-m-d"); ?>" required="">
                    &nbsp;
                    <label>
                        <h5>结束日期:</h5>
                    </label>
                    <input type="date" name="rent_end_date" min="<?php echo date("Y-m-d", time() + 24 * 60 * 60); ?>" required="">

                    <h5> 选择汽车类型: &nbsp;
                        <input onclick="reveal()" type="radio" name="radio" value="ac" ng-model="myVar">
                        <b>豪华型 (带空调)</b>&nbsp;
                        <input onclick="reveal()" type="radio" name="radio" value="non_ac" ng-model="myVar"><b>经济型 (不带空调)</b>
                    </h5>

                    <div ng-switch="myVar">
                        <div ng-switch-default>
                            <h5>费用: <h5>
                        </div>
                        <div ng-switch-when="ac">
                            <h5>费用: <b>
                                    <?php echo ("Rs. " . $ac_price . "/km and Rs. " . $ac_price_per_day . "/day"); ?>
                                </b>
                                <h5>
                        </div>
                        <div ng-switch-when="non_ac">
                            <h5>费用: <b>
                                    <?php echo ("Rs. " . $non_ac_price . "/km and Rs. " . $non_ac_price_per_day . "/day"); ?>
                                </b>
                                <h5>
                        </div>
                    </div>

                    <h5> 收费类型: &nbsp;
                        <input onclick="reveal()" type="radio" name="radio1" value="km"><b> 每公里</b> &nbsp;
                        <input onclick="reveal()" type="radio" name="radio1" value="days"><b> 每天</b>
                    </h5>

                    <br><br>

                    选择司机: &nbsp;
                    <select name="driver_id_from_dropdown" ng-model="myVar1">
                        <?php
                        // 构建 SQL 查询语句，查询满足条件的可用司机信息
                        $sql2 = "SELECT * FROM driver d WHERE d.driver_availability = 'yes' AND d.client_username IN (SELECT cc.client_username FROM clientcars cc WHERE cc.car_id = '$car_id')";

                        // 执行 SQL 查询
                        $result2 = mysqli_query($conn, $sql2);

                        // 如果查询结果大于0，遍历结果集获取司机信息
                        if (mysqli_num_rows($result2) > 0) {
                            while ($row2 = mysqli_fetch_assoc($result2)) {
                                // 获取司机信息
                                $driver_id = $row2["driver_id"]; // 司机ID
                                $driver_name = $row2["driver_name"]; // 司机姓名
                                $driver_gender = $row2["driver_gender"]; // 司机性别
                                $driver_phone = $row2["driver_phone"]; // 司机电话
                        ?>
                                <option value="<?php echo ($driver_id); ?>">
                                    <?php echo ($driver_name); ?>
                                <?php }
                        } else { ?>
                                对不起！当前没有司机可用，请稍后再试...
                            <?php
                        }
                            ?>
                    </select>

                    <div ng-switch="myVar1">
                        <?php
                        // 构建 SQL 查询语句，查询满足条件的可用司机信息
                        $sql3 = "SELECT * FROM driver d WHERE d.driver_availability = 'yes' AND d.client_username IN (SELECT cc.client_username FROM clientcars cc WHERE cc.car_id = '$car_id')";
                        // 执行 SQL 查询
                        $result3 = mysqli_query($conn, $sql3);
                        // 如果查询结果大于0，遍历结果集获取司机信息
                        if (mysqli_num_rows($result3) > 0) {
                            while ($row3 = mysqli_fetch_assoc($result3)) {
                                // 获取司机信息
                                $driver_id = $row3["driver_id"]; // 司机ID
                                $driver_name = $row3["driver_name"]; // 司机姓名
                                $driver_gender = $row3["driver_gender"]; // 司机性别
                                $driver_phone = $row3["driver_phone"]; // 司机电话
                        ?>
                                <div ng-switch-when="<?php echo ($driver_id); ?>">
                                    <h5>司机姓名:&nbsp; <b>
                                            <?php echo ($driver_name); ?>
                                        </b></h5>
                                    <p>性别:&nbsp; <b>
                                            <?php echo ($driver_gender); ?>
                                        </b> </p>
                                    <p>联系方式:&nbsp; <b>
                                            <?php echo ($driver_phone); ?>
                                        </b> </p>
                                </div>
                        <?php
                            }
                        }
                        ?>
                    </div>
                    <input type="hidden" name="hidden_carid" value="<?php echo $car_id; ?>">
                    <input type="submit" name="submit" value="现在租赁" class="btn btn-warning pull-right">
                </form>
            </div>
            <div class="col-md-12" style="float: none; margin: 0 auto; text-align: center;">
                <h6><strong>注意:</strong> 超过截止日期的每一天都将额外收取 <span class="text-danger">Rs. 500</span>。</h6>
            </div>
        </div>
</body>
<footer class="site-footer">
    <div class="container">
        <hr>
        <div class="row">
            <div class="col-sm-6">
                <h5>©
                    <?php echo date("Y"); ?> 租车服务
                </h5>
            </div>
        </div>
    </div>
</footer>

</html>